package com.mcflies.commons;

import com.mcflies.ui.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.AdapterView;
import android.widget.ListView;

public class CornerListView extends ListView {

	public CornerListView(Context context) {
		super(context);
	}

	public CornerListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public CornerListView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent event) {

		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			int x = (int) event.getX();
			int y = (int) event.getY();
			int item = pointToPosition(x, y);

			if (item == AdapterView.INVALID_POSITION) {
				break;
			} else {
				if (0 == item) {// 第一项
					if (item == (getAdapter().getCount() - 1)) {// 只有一项
						setSelector(R.drawable.corner_list_view_round);
					} else {
						setSelector(R.drawable.corner_list_view_top);
					}
				} else if (item == (getAdapter().getCount() - 1)) {// 最后一项
					setSelector(R.drawable.corner_list_view_bottom);
				} else {
					setSelector(R.drawable.corner_list_view_center);
				}
			}
			break;

		case MotionEvent.ACTION_UP:
			break;
		}
		return super.onInterceptTouchEvent(event);
	}
}
